class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        char_map = {}
        max_len = 0
        start = 0
        for end in range(len(s)):
            current_char = s[end]
            # 如果字符已存在且在窗口内，移动start指针
            if current_char in char_map and char_map[current_char] >= start:
                start = char_map[current_char] + 1
            # 更新字符的最新位置
            char_map[current_char] = end
            # 计算当前窗口长度并更新最大值
            current_len = end - start + 1
            if current_len > max_len:
                max_len = current_len
        return max_len

class Solution:
    def lengthOfLongSubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            #如果字符已经存在且在窗口内，移动start指针
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]
            #更新字符的最新位置
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>current_len:
                max_len=current_len
        return max_len


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        char_map = {}
        max_len = 0
        start = 0
        for end in range(len(s)):
            current_char = s[end]
            # 如果字符已存在且在窗口内，移动start指针
            if current_char in char_map and char_map[current_char] >= start:
                start = char_map[current_char] + 1
            # 更新字符的最新位置
            char_map[current_char] = end
            # 计算当前窗口长度并更新最大值
            current_len = end - start + 1
            if current_len > max_len:
                max_len = current_len
        return max_len


class Solution:
    def lengthOFLongSubstring(self,s:str)->int:
        char_map={}
        mex_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            #如果字符已经存在且在窗口中，移动start指针
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            #计算当前窗口长度并更新最大值
            current_len =end-start+1
            if current_len>max_len:
                max_len=current_len
        return max_len

class Solution:
    def lengthOFLongSubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            #计算当前窗口长度并更新最大值
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len
        return max_len

class Solution:
    def lengthoflongsubstring(self,s:str)->int:
        char_map={}#以字典形式存放字符，并记录它们最后出现的位置
        max_len=0
        start=0
        for end  in range(len(s)):
            current_char=s[end]#取到字符
            if current_char in char_map and char_map[current_char]>=start:#记录到字典中过，并且最后出现位置大于等于start则需要将start后移
                start=current_char+1
            char_map[current_char]=end#更新字符的位置，无论是否重复都需更新
            current_len=end-start+1#计算滑动窗口长度
            if current_len>max_len:
                max_len=current_len
        return max_len

class Solution:
    def lengthofsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=current_char + 1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len > max_len:
                max_len=current_len
        return max_len


class Solution:
    def lengthofsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len > max_len:
                max_len=current_len
        return max_len
class Solution:
    def lengthofsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=max_len
        return max_len
class Solution:
    def lengthofsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len
        return max_len

class Solution:
    def lengthofsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len >max_len:
                max_len=current_len
        return max_len

class Solution:
    def lengthofsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            current_char[current_char]=end
            current_len=end-start+1
            if current_len >max_len:
                max_len = current_len
        return max_len


class Solution:
    def lengthsubstring(self,s:str)->int:
        max_len=0
        char_map={}
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len
        return max_len


class Solution:
    def lengthsubstring(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len

        return max_len

class Solution:
    def zuichangbuchongfuzichuan(self,s:str)->int:
        char_map={}
        max_len=0
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len

        return max_len

class Solution:
    def zuichangbuchongfuzichuan(self,s:str)->int:
        max_len=0
        char_map={}
        start=0
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len

        return max_len

class Solution:
    def zuichangzichuan(self,s:str)->int:
        max_len=0
        char_map={}
        start=0
        for end in  range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end - start +1
            if current_len >max_len:
                max_len = current_len
        return max_len

class Solution:
    def zuichangzichuan(self,s:str)->int:
        max_len=0
        start=0
        char_map={}
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len
        return max_len

class Solution:
    def zuichangzichuan(self,s:str)->int:
        max_len=0
        start=0
        char_map={}
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=char_map[current_char]+1
            char_map[current_char]=end
            current_len=end -start +1
            if current_len>max_len:
                max_len=current_len
        return max_len


class Solution:
    def zuichangzichuan(self,s:str)->int:
        max_len=0
        start=0
        char_map={}
        for end in range(len(s)):
            current_char=s[end]
            if current_char in char_map and char_map[current_char]>=start:
                start=end+1
            char_map[current_char]=end
            current_len=end-start+1
            if current_len>max_len:
                max_len=current_len
        return max_len



